package main

import (
	"os"
	"text/template"
)

type MyMethod struct {
	Say  string
	Name string
}

func (my *MyMethod) SayHello() string { //没参数
	return "world"
}

func (my *MyMethod) SayYouName(name string) string { //有参数
	return "my name is : " + name
}

func main() {
	mine := &MyMethod{Say: "hello", Name: "student"}
	//先对变量$str1，$str2，$str3赋值，一个是直接将字符串值赋值，另两个是调用函数，将返回值赋值，然后再将变量值输出
	tmpl, err := template.New("test").Parse("{{$str1 := .Say}}{{$str2 := .SayHello}}{{$str3 := .SayYouName .Name}}{{$str1}} {{$str2}}\n{{$str3}}\n")
	if err != nil {
		panic(err)
	}
	err = tmpl.Execute(os.Stdout, mine)
	if err != nil {
		panic(err)
	}
}
